package com.springboot.leaseHouse.util;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName RedisUtil
 * @Description //TODO ：Redis操作类
 * @Author 秦野
 * @Date 2021/9/2410:18
 */
@Component
public class RedisUtil {

        @Resource
        private RedisTemplate<String, String> redisTemplate;

    /**
     * 保存数据到Redis中
     * @param key 键
     * @param value 值
     */
    public void set(String key, String value) {
            ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
            valueOperations.set(key, value);
        }

        /**
         * 保存键值对到Redis中
         * @param key 键
         * @param value 值
         * @param seconds 失效时间
         */
        public void setex(String key, String value, int seconds) {
            ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
            valueOperations.set(key, value, seconds);
        }

}
